//
//  BSZHTTPSessionManager.m
//  BuSuanZi
//
//  Created by staff on 3/15/25.
//

#import "BSZHTTPSessionManager.h"

@implementation BSZHTTPSessionManager

static AFHTTPRequestSerializer *requestSerializer = nil;
static BSZHTTPSessionManager *_sharedClient = nil;

+ (instancetype)sharedClient {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [BSZHTTPSessionManager manager];

        _sharedClient.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"x-www-form-urlencoded",@"text/plain", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css",@"application/pdf",@"form/data",@"application/octet-stream", nil] ;
        _sharedClient.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
        
        requestSerializer =  [AFJSONRequestSerializer serializer];
        [requestSerializer setTimeoutInterval:20];
        //添加请求头
        [requestSerializer setValue:(Token == nil ? @"" : Token) forHTTPHeaderField:@"XX-Token"];
        [requestSerializer setValue:@"android" forHTTPHeaderField:@"XX-Device-Type"];
        [requestSerializer setValue:@"1.0" forHTTPHeaderField:@"XX-Api-Version"];
        [requestSerializer setValue:@"" forHTTPHeaderField:@"XX-Store-Channel"];
        _sharedClient.requestSerializer = requestSerializer;

        [_sharedClient. reachabilityManager setReachabilityStatusChangeBlock :^( AFNetworkReachabilityStatus status) {
            switch (status) {
                case AFNetworkReachabilityStatusReachableViaWWAN :
                    NSLog ( @"-------AFNetworkReachabilityStatusReachableViaWWAN------" );
                    break ;
                case AFNetworkReachabilityStatusReachableViaWiFi :
                    NSLog ( @"-------AFNetworkReachabilityStatusReachableViaWiFi------" );
                    break ;
                case AFNetworkReachabilityStatusNotReachable :
                    NSLog ( @"-------AFNetworkReachabilityStatusNotReachable------" );
                    break ;
                default :
                    break ;
            }
        }];
        
        [_sharedClient. reachabilityManager startMonitoring];
    });
    
    return _sharedClient;
}


@end
